package com.poisson;

import javax.swing.*;
import java.awt.*;

public class PaintTableService {

    /**
     * 画随机数表格
     * @param numberArray
     */
    public static void paint(Double[] numberArray) {
        String[][] serialNoAndNumberArray = new String[numberArray.length][2];

        for (int i = 0; i < numberArray.length; i++) {
            String numberStr = numberArray[i].toString();
            serialNoAndNumberArray[i] = new String[]{String.valueOf(i), numberStr};
        }
        paintTable(serialNoAndNumberArray, new String[]{"序号", "值"});
    }

    /**
     * 画随机数表格
     * @param numberArray
     * @param biNumberArray
     */
    public static void paint(Double[] numberArray, Double[] biNumberArray) {
        String[][] serialNoAndNumberArray = new String[numberArray.length][3];
        for (int i = 0; i < numberArray.length; i++) {
            String numberStr = numberArray[i].toString();
            serialNoAndNumberArray[i] = new String[]{String.valueOf(i), numberStr, biNumberArray[i].toString()};
        }
        paintTable(serialNoAndNumberArray, new String[]{"序号", "值", "Bi"});
    }

    private static void paintTable(String[][] serialNoAndNumberArray, String[] headers) {
        JFrame resultFrame = new JFrame();
        JTable resultTable = new JTable(serialNoAndNumberArray, headers);
        resultTable.setGridColor(Color.BLACK);
        resultTable.setEnabled(false);

        JScrollPane jScrollPane = new JScrollPane(resultTable);
        resultFrame.setSize(1000, 1000);
        resultFrame.add(jScrollPane);
        resultFrame.setVisible(true);
    }
}
